package com.shujia.day14;

public class Teacher implements Comparable<Teacher>{
    private String name;
    private int age;

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Teacher o) {
        //cmp = k.compareTo(t.key);
        // this - 待插入元素
        // o - 要比较的根元素
        //当姓名和年龄一样的时候去重，年龄需要从小到大排序
//        return this.age - o.getAge();
        //显式条件
        int i1 = this.age - o.getAge();
        //隐式条件
        //当年龄一样的时候，姓名不一定一样
        return (i1==0)?this.name.compareTo(o.name):i1;
    }
}
